/*******************************************************************************
 * File:      comdef.h                                                         *
 * Function:  some common define                                               *
 * Author:    kvmaker                                                          *
 * Email:     kvmaker@gmail.com                                                *
 * Data:      24/Feb/2012                                                      *
 *                                                                             *
 * Copyright: kvmaker                                                          *
 *                                                                             *
 * Licensed under the Apache License, Version 2.0 (the "License");             *
 * you may not use this file except in compliance with the License.            *
 * You may obtain a copy of the License at                                     *
 *                                                                             *
 *    http://www.apache.org/licenses/LICENSE-2.0                               *
 *                                                                             *
 * Unless required by applicable law or agreed to in writing, software         *
 * distributed under the License is distributed on an "AS IS" BASIS,           *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    *
 * See the License for the specific language governing permissions and         *
 * limitations under the License.                                              *
 ******************************************************************************/
#ifndef __COMDEF__
#define __COMDEF__

/*******************************************************************************
 *                               INCLUDE                                       *
 ******************************************************************************/
#include <stdio.h>

#include <SDL/SDL.h>

/*******************************************************************************
 *                               DEFINE                                        *
 ******************************************************************************/
#define CT_DEBUG(fmt, args...)  \
            printf("[%5s %5d]:"fmt, __FUNCTION__, __LINE__, ##args)
#define CT_ASSERT(expr)         \
            ((expr) != 0 ?(void)0:CT_DEBUG("ASSERT fail.\n"))

#define CT_EPSILON      1E-9
#define CT_MAX(a, b)    (((a) - (b)) > CT_EPSILON ?(a):(b))
#define CT_MIN(a, b)    CT_MAX(b, a)

#define offsetof(TYPE, MEMBER) ((char *) &((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) ({			\
	const typeof(((type *)0)->member) * __mptr = (ptr);	\
	(type *)((char *)__mptr - offsetof(type, member)); })

#define CT_GET_TICK()   SDL_GetTicks()

/*******************************************************************************
 *                               TYPEDEF                                       *
 ******************************************************************************/
typedef unsigned int    UINT32;
typedef unsigned short  UINT16;
typedef unsigned char   UINT8;

typedef int             INT32;
typedef short           INT16;
typedef char            INT8;

typedef enum
{
    CT_RET_SUCC = 0,
    CT_RET_FAIL = 1,
} CT_RET;

typedef enum
{
    CT_FALSE = 0,
    CT_TRUE  = 1,
} CT_BOOL;

typedef struct 
{
    double x;
    double y;
} POINT;

typedef struct 
{
    double x;
    double y;
} VECTOR;


#endif /*__COMDEF__*/

